<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style>
        .aui-bar-nav {
            background-color: #FFF;
            color: #000;
            position: fixed;
            border-bottom: 1px solid #EEEEEE;
        }

        .aui-bar-nav .aui-iconfont {
            color: #000!important;
            font-weight: bold;
        }

        .tishi {
            font-size: 0.7rem;
            text-align: center;
            color: #999;
            padding-bottom: 1rem;
        }

        .aui-content {
            margin-top: 2.25rem;
            position: relative;
        }

        .income-details .top-box {
            position: fixed;
            background-color: #FFF;
            width: 100%;
            padding: 0.4rem 1.6rem;
        }

        .income-details .cent-box {
            margin-top: 2.5rem;
        }
    </style>
</head>

<body>
    <header id="header" class="aui-bar aui-bar-nav">
        <a class="aui-pull-left aui-btn" tapmode onclick="comeBack()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">账户明细</div>
    </header>
    <div id="aui-content" class="aui-content income-details">
        <div class="top-box">
            <div class="item active" data-id="1" tapmode onclick="getInfo(this)">收入明细</div>
            <div class="item" data-id="2" tapmode onclick="getInfo(this)">提现记录</div>
        </div>
        <div class="cent-box">
            <div class="wrap shouyi" style="display:block">
            </div>

            <div class="wrap tixian" style="display:none">
            </div>
        </div>
        <div class="tishi">下拉加载更多</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../script/md5.min.js"></script>
<script type="text/javascript">
    var pageNum = 1,
        pageNumT = 1,
        status = 1,
        whterScroll = true;
    apiready = function() {
        initHeard();
        $api.fixStatusBar($api.byId('aui-content'));
        shouyi();
        tixian();
        //下拉刷新
        _downRefresh(function() {
            console.log(status);
            if (status == 1) {
                pageNum = 1;
                shouyi();
            } else {
                pageNumT = 1;
                tixian();
            }
            api.refreshHeaderLoadDone();
        });
        scrollBottom(); //上拉加载更多
    };

    function getInfo(that) {
        var tatus = that.getAttribute("data-id");
        if (status == tatus) {
            return false;
        } else {
            status = tatus;
            whterScroll = true;
            $(".tishi").html("下拉加载更多")
            $(that).addClass("active").siblings().removeClass("active");
            if (status == 1) {
                $(".cent-box .wrap").hide();
                $(".cent-box .wrap").eq(0).show();
            } else {
                $(".cent-box .wrap").hide();
                $(".cent-box .wrap").eq(1).show();
            }
        }
    };
    //上拉加载更多
    function scrollBottom() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 60 //设置距离底部多少距离时触发，默认值为0，数字类型
            }
        }, function(ret, err) {
            if (whterScroll) { //1开启执行 0停止执行   防止连续滚动，等加载数据之后在进行滚动。
                whterScroll = !whterScroll;
                if (status == 1) {
                    pageNum += 1;
                    shouyi();
                } else {
                    pageNumT += 1;
                    tixian();
                }
            }
        });
    };

    function shouyi() {
        _ajax("index/incomList", {
            p: pageNum
        }, function(res, err) {
            if (res) {
                console.log(JSON.stringify(res));
                _msg(res.msg);
                if (res.errCode == 1) {
                    if (res.data.length > 0) {
                        var info = res.data,
                            leng = info.length,
                            html = '';
                        for (var i = 0; i < leng; i++) {
                            html += '<div class="item">';
                            var img = '';
                            if (info[i].img == '' || info[i].img == null) {
                                img = '../icon/logo.png';
                            } else {
                                img = imgurl + info[i].img;
                            }
                            html += '<div class="left"><img src="' + img + '"> </div>';
                            html += '<div class="cent">';
                            html += '<div>' + info[i].title + '</div>';
                            html += '<p>' + info[i].create_time + '</p></div>';
                            html += '<div class="right">' + info[i].coin + '</div></div>';
                        }
                        if (pageNum == 1) {
                            $(".cent-box .shouyi").html(html);
                        } else {
                            $(".cent-box .shouyi").append(html);
                        }
                        whterScroll = true;
                        $(".tishi").html("下拉加载更多")
                    } else {
                        whterScroll = false;
                        $(".tishi").html("没有更多了")
                    }
                } else if (res.errCode == -1) {
                    openWin('login');
                }
            } else {
                _msg("网络错误");
            }
        })
    };

    function tixian() {
        _ajax("index/cashList", {
            p: pageNumT
        }, function(res, err) {
            console.log(JSON.stringify(res));
            if (res) {
                if (res.data.length > 0) {
                    var info = res.data,
                        leng = info.length,
                        html = '';
                    for (var i = 0; i < leng; i++) {
                        html += '<div class="item">';
                        html += '<div class="cent"><div>支付宝提现</div><p>' + info[i].create_time + '</p></div>';
                        if (info[i].cash_status == 2) {
                            html += '<div class="right"><span>' + info[i].cash_money + '元</span><p>驳回：' +
                                info[i].handle_notes + '</p></div></div>';
                        } else if (info[i].cash_status == 1) {
                            html += '<div class="right"><span>' + info[i].cash_money + '元</span><p>审核通过,手续费：' +
                                info[i].procedures + '元</p></div></div>';
                        } else  if (info[i].cash_status == 5) {
                            html += '<div class="right"><span>' + info[i].cash_money + '元</span><p>金额冻结</p></div></div>';
                        } else {
                            html += '<div class="right"><span>' + info[i].cash_money + '元</span><p>手续费：' +
                                info[i].procedures + '元</p></div></div>';
                        }
                        html += "</div>";
                    }
                    if (pageNumT == 1) {
                        $(".cent-box .tixian").html(html);
                    } else {
                        $(".cent-box .tixian").append(html);
                    }
                    whterScroll = true;
                    $(".tishi").html("下拉加载更多")
                } else {
                    whterScroll = false;
                    $(".tishi").html("没有更多了")
                }
            } else {
                _msg("网络错误");
            }
        })

    };
</script>

</html>
